// Copyright (c) 2014 Morten Bakkedal
// This code is published under the MIT License.

using System;
using System.Collections;
using System.Collections.Generic;

namespace FuncLib.DualFunctions.Collections.Generic
{
	/// <summary>
	/// Read-only wrapper around <see cref="IList{T}" />.
	/// </summary>
	[Serializable]
	public class ReadOnlyList<T> : IReadOnlyList<T>
	{
		private IList<T> list;

		public ReadOnlyList(IList<T> list)
		{
			// Warning! No copying is performed.
			this.list = list;
		}

		public bool Contains(T item)
		{
			return list.Contains(item);
		}

		public void CopyTo(T[] array, int arrayIndex)
		{
			list.CopyTo(array, arrayIndex);
		}

		public int IndexOf(T item)
		{
			return list.IndexOf(item);
		}

		public IEnumerator<T> GetEnumerator()
		{
			return list.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return ((IEnumerable)list).GetEnumerator();
		}

		public T this[int index]
		{
			get
			{
				return list[index];
			}
		}

		public int Count
		{
			get
			{
				return list.Count;
			}
		}
	}
}
